<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>运维单位--公告列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/weadmin.css">
    <script type="text/javascript" src="/templates/act/process-xl.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<form class="layui-form searchForm" action="">
    查询:
    <div class="layui-input-inline">
        <input style="width:200px;" type="text" name="noticeTitle" placeholder="请输入关键字" autocomplete="off"
               class="layui-input">
    </div>
    <div class="layui-input-inline">
        <select name="acceptOrgType" id="acceptOrgType">
            <option value=""></option>
        </select>
    </div>
    <button class="layui-btn" lay-submit lay-filter="formDemo">查询</button>
    <button class="layui-btn" lay-submit lay-filter="formClear">清空</button>
</form>
<table class="layui-hide" id="dataList" lay-filter="dataList"></table>

<script type="text/html" id="toolbarOrg">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-normal" lay-event="add">发布公告</button>
    </div>
</script>
<script type="text/html" id="switchTpl">
    <input type="checkbox" name="sex" value="{{d.noticeId}}" lay-skin="switch" lay-text="on|off" lay-filter="switch"
           {{ d.showStatus =='ON' ? 'checked' : '' }}>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="change">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/javascript" src="/lib/layui/layui.js"></script>
<script src="/static/js/main.js"></script>
<script>
    layui.use(['jquery','form', 'configureCom', 'configure','selectFun', 'sessionFun', 'table', 'matchDict'], function () {
        var $ = layui.jquery;
        var configure = layui.configure;
        var form = layui.form;
        var table = layui.table;
        var sessionFun = layui.sessionFun;
        var selectFun = layui.selectFun;
        var matchDict = layui.matchDict;
        var configureCom = layui.configureCom;
        configureCom.selectDataFun(configure.NOTICE_ORG_TYPE, '', '#acceptOrgType'); //接收单位
        form.render();
        var cols = [[
            {field: 'noticeTitle', title: '通知标题'},
            {field: 'createTime', title: '发布时间'},
            {field: 'acceptOrgType', title: '接受单位', templet: function (d) {
                    var arr = d.acceptOrgType.split(',');
                    for (var i = 0; i < arr.length;i++){
                        return '<p>' + (matchDict.name(arr[i],configure.NOTICE_ORG_TYPE) ||'-') + '</p>';
                    }
                    /*if (arr.length == 2) {

                        $('#fanwei').html(matchDict.name(arr[0], configure.SUBMIT_EXAM_INFO) + '、' + matchDict.name(arr[1], configure.SUBMIT_EXAM_INFO));
                    } else {
                        $('#fanwei').html(matchDict.name(arr[0], configure.SUBMIT_EXAM_INFO));
                    }*/
                    /*return '<p>'
                        + (matchDict.name(d.acceptOrgType,configure.NOTICE_ORG_TYPE) ||'-')
                        + '</p>';*/
                }
            },
            {field: 'showStatus', title: '显示状态', toolbar: '#switchTpl'
            },
            {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 320}
        ]];
        configureCom.tableRender(configure.NOTICE_QUERY_ALL_HTTP, {}, cols, 'dataList', 10, '', 'toolbarOrg');
        //头工具栏事件
        table.on('toolbar(dataList)', function (obj) {
            sessionFun.remove(configure.SESSION_NOTICE_LIST_DATA);
            switch (obj.event) {
                case 'add':
                    editItem('新建公告', configure.NOTICE_SAVE_HTTP,configureCom.nocache(configure.NOTICE_NOTICE_RELEASE_NOTICE_HTML));
        break;
    }
        });

        //每行操作
        table.on('tool(dataList)', function (obj) {
            var data = obj.data;
            sessionFun.set(configure.SESSION_NOTICE_LIST_DATA, data);
            if (obj.event === 'change') {
                editItem('修改', configure.NOTICE_SAVE_HTTP,configureCom.nocache(configure.NOTICE_NOTICE_RELEASE_NOTICE_HTML));
            } else if (obj.event === 'del') {
                //关闭时重新渲染表格当前页
                top.layer.confirm('确认删除？', {title: '提示'}, function (index) {
                    top.layer.close(index);
                    configureCom.postDataAjax(configure.NOTICE_DELETE_HTTP, {noticeId: data.noticeId}).then(function (res) {
                        if (res.code == 0) {
                            top.layer.msg('删除成功！');
                            configureCom.tableReload(true);
                        } else {
                            top.layer.alert('删除失败！');
                        }
                    });
                });
            }
        });
        //监听是否显示操作
        form.on('switch(switch)', function (obj) {
            var noticeId = this.value;
            var successMsg = obj.elem.checked ? '已开启' : '已关闭';
            configureCom.postDataAjax(configure.NOTICE_HIDE_OR_SHOW_HTTP,{noticeId:noticeId}).then(function (res) {
                if (res.code == 0) {
                    top.layer.msg(successMsg);
                    configureCom.tableReload(true);
                }
            })
        });
        //新增或修改公告详情
        function editItem(title, url,content) {
            top.layer.open({
                type: 2,
                title: title,
                area: configureCom.Psize1,
                content: content,
                btn: ['发布','取消'],
                btnAlign: 'c',
                yes: function (index, layero) {
                    var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对
                    iframeWin.getData().then(function (res) {
                        configureCom.postDataAjax(url, res.result).then(function (res) {
                            top.layer.close(index);
                            top.layer.msg('发布成功');
                            configureCom.tableReload(true);
                        });
                    });
                }
            });
        }

        //监听搜索
        configureCom.tableSearch();
    });
</script>
</body>
</html>